import { http } from '@/utils/http'
import type { LocationItem, AddressParams } from '@/types/address'

/**
 * 新建收货地址
 * /member/address
 */
export const addressApi = (data: AddressParams) => {
  return http<{ id: string }>({
    method: 'POST',
    url: '/member/address',
    data,
  })
}

/**
 * 修改收货地址
 */
export const changeAddressApi = (id: string, data: AddressParams) => {
  return http({
    method: 'PUT',
    url: `/member/address/${id}`,
    data,
  })
}

/**
 * 获取收货地址列表
 * /member/address
 */
export const queryAddressList = () => {
  return http<LocationItem[]>({
    method: 'GET',
    url: '/member/address',
  })
}

/**
 * 获取收货地址详情
 */
export const queryAddressDetail = (id: string) => {
  return http<LocationItem>({
    method: 'GET',
    url: `/member/address/${id}`,
  })
}

/**
 * 删除地址
 */
export const delAddress = (id: string) => {
  return http({
    method: 'DELETE',
    url: `/member/address/${id}`,
  })
}
